package com.java1412.config;

import com.java1412.properties.MyWebProperties;
import com.java1412.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author java1412
 * @create 2021-07-20 16:15
 */
@SuppressWarnings("all")
@Configuration
@EnableConfigurationProperties(value = MyWebProperties.class)
@ConditionalOnProperty(prefix = "myweb.config", name = "enable", havingValue = "true")
public class MyWebConfig {

    @Autowired
    private MyWebProperties properties;

    @Bean
    public ConfigService defaultWebConfig() {
        return new ConfigService(properties.getPort(), properties.getName(), properties.getInfo());
    }
}
